const withCSS = require('@zeit/next-css')
const withLess = require('@zeit/next-less')
const webpack = require('webpack')
/* Without CSS Modules, with PostCSS */
const argv = require("yargs").argv;
module.exports = withLess(withCSS({
    cssModules: true,
    cssLoaderOptions: {
        importLoaders: 1,
        localIdentName: "[local]___[hash:base64:5]",
    },
    webpack: function (config) {
        config.externals = {
            react: "React",
            // "react-dom": "ReactDOM",
            "react-router": "ReactRouter",
            redux: "Redux",
            echarts: "echarts",
            konva: "Konva",
            lodash: {
                commonjs: 'lodash',
                amd: 'lodash',
                root: '_' // indicates global variable
            },
            axios: "axios",
            mockjs: "mockjs"
        }
        config.devtool = "cheap-module-eval-source-map"
        config.plugins = config.plugins.concat(
            [
                new webpack.DefinePlugin({
                    NODE_ENV: "'" + process.env.NODE_ENV + "'",
                    __API__: process.env.NODE_ENV == "production" ? "'/api'" : "'/api'",
                    UPLOAD_ACTION: "'https://upload-z2.qiniup.com'",
                    IMAGE_DOMAIN: "'https://qn.diyeetech.com'"
                }),
            ]
        )
        return config;
    }
}))

/* With CSS Modules */
// module.exports = withCSS({ cssModules: true })

/* With additional configuration on top of CSS Modules */
/*
module.exports = withCSS({
  cssModules: true,
  webpack: function (config) {
    return config;
  }
});
*/
